package com.wfbi.security.chapter20.authserver;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.oauth2.provider.token.TokenStore;
import org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter;
import org.springframework.security.oauth2.provider.token.store.JwtTokenStore;

/**
 * token存储策略
 *
 * @author wfbi
 * @version 1.0
 * @date 2022/1/5 11:43 AM
 */
@Configuration
public class AccessTokenConfig {
    /**
     * 使用jwt
     *
     * @author: wfbi
     * @date: 2022/1/5 11:50 AM
     * @return: org.springframework.security.oauth2.provider.token.TokenStore
     **/
    @Bean
    TokenStore tokenStore() {
        return new JwtTokenStore(jwtAccessTokenConverter());
    }

    /**
     * 将用户信息和 JWT 进行转换（将用户信息转为 jwt 字符串，或者从 jwt 字符串提取出用户信息）
     *
     * @author: wfbi
     * @date: 2022/1/5 11:49 AM
     * @return: org.springframework.security.oauth2.provider.token.store.JwtAccessTokenConverter
     **/
    @Bean
    JwtAccessTokenConverter jwtAccessTokenConverter() {
        JwtAccessTokenConverter converter = new JwtAccessTokenConverter();
        converter.setSigningKey("wfbi");
        return converter;
    }
}
